package lambdasinaction.chap11;

import java.util.Queue;

import static lambdasinaction.chap11.Util.delay;
import static lambdasinaction.chap11.Util.format;

/**
 * Created by ThinkPad on 2017/8/28.
 */
public class Discount {
    public enum Code {
        NPNE(0),SILVER(5),GOLD(10),PLATINUM(15),DIAMOND(20);
        private final int percentage;
        Code(int percentage) {
            this.percentage = percentage;
        }
    }

    public static String applyDiscount(Quote quote) {
        return quote.getShopName() + " price is " + Discount.apply(quote.getPrice(),quote.getDiscountCode());
    }

    private static double apply(double price, Code code) {
        delay();
        return format(price * (100 - code.percentage) / 100);
    }
}
